package aggregate;

import iterator.IIterator;

import java.util.LinkedList;

/**
 * Created by DELL
 * Date: 2019/10/9.
 * Time: 15:13
 */
public class Science implements ISubject {
    private LinkedList<String> subjects;

    public Science() {
        subjects = new LinkedList<String>();
        subjects.addLast("Maths");
        subjects.addLast("Comp.Sc");
        subjects.addLast("Physics");

    }

    @Override
    public IIterator createIterator() {
        return new ScienceIterator(subjects);
    }

    public class ScienceIterator implements IIterator{
        private LinkedList<String> subjects;
        private int postion;

        public ScienceIterator(LinkedList<String> subjects) {
            this.subjects = subjects;
            postion = 0;
        }

        @Override
        public void first() {
            postion = 0;
        }

        @Override
        public String next() {
            return subjects.get(postion ++);
        }

        @Override
        public Boolean isDone() {
            return postion >= subjects.size();
        }

        @Override
        public String currentItem() {
            return subjects.get(postion);
        }


    }
}
